//
//  TVCellOfQAADetailedInformation.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/23.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "TVCellOfQAADetailedInformation.h"
// models
#import "AnswersOfDataQAADetailedInformation.h"
#import "DataOfQAADetailedInformation.h"
#import "QuestionOfDataQAADetailedInformation.h"
#import "ReplyOfAnswersDataQAADetailedInformation.h"
#import "ReplyuserOfReplyAnswersDataQAADetailedInformation.h"
#import "RootClassOfQAADetailedInformation.h"
#import "StateOfDataQAADetailedInformation.h"
#import "TagsOfQuestionDataQAADetailedInformation.h"
#import "UserOfAnswersDataQAADetailedInformation.h"
#import "UserOfQuestionDataQAADetailedInformation.h"
#import "UserOfReplyAnswersDataQAADetailedInformation.h"
@implementation TVCellOfQAADetailedInformation
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
        //
        [self createReplyBackgroundView];
        
    }
    return self;
}
#pragma mark - 创建里面的子控件
- (void)createSubViews{
//    @property (weak, nonatomic) IBOutlet UIImageView *userAvatarImageView;
    // 第一个回复人的头像
    _userAvatarImageView = [[UIImageView alloc] init];
    _userAvatarImageView.image = [UIImage imageNamed:@"0"];
    [self.contentView addSubview:_userAvatarImageView];
//    @property (weak, nonatomic) IBOutlet UILabel *userNicknameLabel;
     // 第一个回复人的昵称v
    _userNicknameLabel = [[UILabel alloc] init];
    _userNicknameLabel.text = @"李成";
    [self.contentView addSubview:_userNicknameLabel];
//    @property (weak, nonatomic) IBOutlet UILabel *answersContentLabel;
     // 第一个回复人的回复内容
    _answersContentLabel = [[UILabel alloc] init];
    _answersContentLabel.numberOfLines = 0;
    _answersContentLabel.text = @"回复的内容";
    [self.contentView addSubview:_answersContentLabel];
//    @property (weak, nonatomic) IBOutlet UILabel *answersCreatedLabel;
    // 第一个回复人回复的时间
    _answersCreatedLabel = [[UILabel alloc] init];
    _answersCreatedLabel.text = @"创建时间";
    [self.contentView addSubview:_answersCreatedLabel];
//    @property (weak, nonatomic) IBOutlet UILabel *answersReplynumLabel;
    _answersReplynumLabel = [[UILabel alloc] init];
    _answersReplynumLabel.text = @"6人";
    [self.contentView addSubview:_answersCreatedLabel];
//    @property (weak, nonatomic) IBOutlet UILabel *answersVotenumLabel;
    _answersVotenumLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_answersVotenumLabel];
//    @property (weak, nonatomic) IBOutlet UIView *replyBackgroundView;
    _replyBackgroundView = [[ReplyBackgroundView alloc] init];
    [self.contentView addSubview:_replyBackgroundView];
//    @property (weak, nonatomic) IBOutlet UIButton *clickCommentReplyButton;
    // 第一个回复人的被回复数的button
    _clickCommentReplyButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [_clickCommentReplyButton addTarget:self action:@selector(clickCommentReplyButton:) forControlEvents:UIControlEventTouchUpInside];
    [_clickCommentReplyButton setImage:[UIImage imageNamed:@"Comment_32-1"] forState:UIControlStateNormal];
    [self.contentView addSubview:_clickCommentReplyButton];
    // 第一个回复的点赞数的 button
    _clickVotenumButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [_clickVotenumButton setImage:[UIImage imageNamed:@"Support_32-1"] forState:UIControlStateNormal];
    [self.contentView addSubview:_clickVotenumButton];
}
#pragma mark -  重新布局
- (void)layoutSubviews{
    [super layoutSubviews];
    // 第一个回复人的头像
    self.userAvatarImageView.frame = CGRectMake(20, 20, 20, 20);
    // 第一个回复人的昵称v
    self.userNicknameLabel.frame = CGRectMake(43, 20, 180, 20);
    CGRect newRect = [_answersContentLabel.text boundingRectWithSize:CGSizeMake(self.contentView.bounds.size.width - 63, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName :[UIFont systemFontOfSize:17]} context:nil];
    // 第一个回复人的回复内容
    self.answersContentLabel.frame = CGRectMake(43, 60, self.contentView.bounds.size.width - 43 - 20, newRect.size.height);
    // 第一个回复人回复的时间
    self.answersCreatedLabel.frame = CGRectMake(43, newRect.size.height + 80, self.contentView.bounds.size.width - 43 - 20, 20);
    // 回复的button
    self.clickCommentReplyButton.frame = CGRectMake(self.contentView.bounds.size.width - 120, newRect.size.height + 80, 20, 20);
    //
//    self.replyBackgroundView.frame = CGRectMake(43, newRect.size.height + 100, self.contentView.bounds.size.width - 43 - 20, self.answersOfDataQAADetailedInformation.reply.count * 20);
    //
}
#pragma mark - clickCommentReply Button 方法实现
- (void)clickCommentReplyButton:(UIButton *)button{
    NSLog(@"查看回复");
}
#pragma mark - 创建 tableView
- (void)createReplyBackgroundView{
    CGRect newRect = [_answersContentLabel.text boundingRectWithSize:CGSizeMake(self.contentView.bounds.size.width - 63, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName :[UIFont systemFontOfSize:17]} context:nil];
    self.replyBackgroundView = [[ReplyBackgroundView alloc] initWithFrame:CGRectMake(43, newRect.size.height + 120, self.contentView.bounds.size.width - 43 - 20, self.answersOfDataQAADetailedInformation.reply.count * 20)];
    self.replyBackgroundView.answersOfDataQAADetailedInformation = _answersOfDataQAADetailedInformation;
    NSLog(@"%@", _replyBackgroundView.answersOfDataQAADetailedInformation);
//    self.replyBackgroundView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:_replyBackgroundView];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
